package targetToOffer.sixteenthDay;

/**
 * @author Godc
 * @description
 */
public class MyPow {
    public static void main(String[] args) {
        MyPowSolution s = new MyPowSolution();
        s.myPow(2.0,10);
    }
}
class MyPowSolution {
    public double myPow(double x, int n) {
        if(n<0){
            n = -n;
            x = 1/x;
        }
        return quickPow(x,n);
    }
    public double quickPow(double x,int n){
        if(n==0) return 1.0;
        double half = quickPow(x,n/2);
        if(n%2==0){
            return half*half;
        }
        else return half*half*x;
    }
}